<?php
// 本文档自动生成，仅供测试运行
class RegisterAction extends Action
{

	/**
	 *
	 * 验证码生成
	 */
	public function verify(){
		$type =	isset($_GET['type'])?$_GET['type']:'gif';
		import("@.ORG.Image");
		Image::buildImageVerify(4,1,$type);
	}

	public function login(){
		$this->display();
	}

	/**
	 * 提交登陆信息
	 * Enter description here ...
	 */
	public function postLoginInfo(){
			
		$Dao = M("loginuser");
			
		// 构造查询条件
		$condition ["name"] = $_POST['username'];
		$condition ["pwd"] = $_POST['password'];
		// 查询数据
		$list = $Dao->where($condition)->find();

		if($list){
			$this->assign("jumpUrl","__APP__/Index/");

			//$this->assign("waitSecond","10");

			//设置session
			Session::set(C('USER_AUTH_KEY'),$_POST['username']);
			//Session::set('username',$_POST['username']);
			$this->success ( "登陆成功！" );
		}else{
			//$this->assign("waitSecond","10");
			$this->success("用户名或者密码错误，请重新输入！") ;
		}

	}

	/**
	 * 用户注销
	 * Enter description here ...
	 */
	public function loginout(){


		if(Session::is_set(C('USER_AUTH_KEY'))){
			//Session::destroy() ;
			unset($_SESSION[C('USER_AUTH_KEY')]);
			$this->assign("jumpUrl","__APP__/");
			$this->success('登出成功！');
		}else{
			$this->success('已经登出！');
		}

	}


	/**
	 * 提交注册信息
	 * Enter description here ...
	 */
	public function postinfo(){
		if($_SESSION['verify'] != md5($_POST['verify'])) {
			$this->error('验证码错误！');
		}
		$model = D ("loginuser");
		if (false === $model->create ()) {
			$this->success ( $model->getError () );
		}
		//保存当前数据对象
		$data ["name"] = $_POST['username'];
		$data ["pwd"] = $_POST['password'];
		$data ["createdate"] = date('Y-m-d H:i:s',time());
		$data ["status"] = 1;
		$lastInsId = $model->add($data);
		if ($lastInsId != -1) {
			//注册后跳转至首页
			$this->assign("jumpUrl","__APP__/Index/");
			//设置session
			Session::set(C('USER_AUTH_KEY'),$_POST['username']);
			//Session::set('username',$_POST['username']);
			$this->success ( "新增用户成功" );
		}else{
			$this->success($model->getError ()) ;
		}
	}


	public function index(){
		$this->display() ;
	}

	public function pwsvalidate(){
		$pwd = $_REQUEST["password"];
		$pwdagain = $_REQUEST["passwordagain"];
		if($pwd!=$pwdagain){
			echo("两次密码输入不一致，请重新输入!");
		}else{
			echo "success";
		}
	}

	public function uservalidate(){
		$user = $_REQUEST["username"];
		if($user == ""){
			echo "用户名不能为空！";
			return;
		}
		$model = D ( "loginuser" );
		// 构造查询条件
		$condition['name'] = $user;
		// 查询数据
		$list = $model->where($condition)->find();
		if(count($list)>0){
			//$this->ajaxReturn ( "111111", "已存在相同的用户，请选择其它用户名进行注册!", 1 );
			echo("已存在相同的用户，请选择其它用户名进行注册!");
		}else{
			//$this->ajaxReturn ( "111111", "可以使用这个用户进行注册!", 1 );
			//echo("可以使用这个用户进行注册!");
			echo "success";
		}
	}



	/**
	 +----------------------------------------------------------
	 * 默认操作
	 +----------------------------------------------------------
	 */
	/*
	 public function index()
	 {
	 $this->display(THINK_PATH.'/Tpl/Autoindex/hello.html');
	 }
	 */
	/**
	 +----------------------------------------------------------
	 * 探针模式
	 +----------------------------------------------------------
	 */
	public function checkEnv()
	{
		load('pointer',THINK_PATH.'/Tpl/Autoindex');//载入探针函数
		$env_table = check_env();//根据当前函数获取当前环境
		echo $env_table;
	}

}
?>